package training;
import java.util.*;
// https://www.nowcoder.com/questionTerminal/c2afcd7353f84690bb73aa6123548770?f=discussion
// 注意类名必须为 test.Main, 不要有任何 package xxx 信息
// 求身高的最长升序子序列，动态规划 ，dp[i]表示到第i个位置的最长子序列
class Node implements Comparable<Node> {
    int id;
    int w;
    int h;
    public Node(int id, int w, int h) {
        this.id = id;
        this.w = w;
        this.h = h;
    }
    @Override
    public int compareTo(Node o1) {
        int ret = w - o1.w;
        if (ret == 0) {
            return o1.h - h;
        }
        return ret;
    }
}
public class Day47_01 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            Node[] width = new Node[n];
            for (int i = 0; i < n; i++) {
                width[i] = new Node(in.nextInt(),in.nextInt(), in.nextInt());
            }
            Arrays.sort(width);
            int[] dp = new int[n];
            dp[0] = 1;
            int res = 0;
            for (int i = 1; i < n; i++) {
                dp[i] = 1;
                for (int j = i - 1; j >= 0; j--) {
                    if (width[i].h >= width[j].h) {
                        dp[i] = Math.max(dp[i], dp[j] + 1);
                    }
                }
                res = Math.max(res, dp[i]);
            }
            System.out.println(res);
        }
    }
}